proc() {
    echo -e "\033[42;32m > $@ \033[0m" >&2
    local command=("$@")
    if "${command[@]}"; then
        echo -e "\033[42;32m SUCCEED \033[0m \n" >&2
    else
        echo -e "\033[41;32m FAILED \033[0m \n" >&2
        exit 1
    fi
}

clear;

PRJNAME="v3sAppLed"
IP="192.168.3.101"
BDPATH="/root/app"
BDKOPATH="/lib/modules"

# building KO
proc make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

# building app
proc arm-linux-gnueabihf-gcc v3sAppLed.c -o build/v3sAppLed

# starting app on board
proc scp ./build/${PRJNAME} root@${IP}:${BDPATH}
proc scp ./start.sh root@${IP}:/etc/init.d
proc scp ./build/v3sKoLed.ko root@${IP}:${BDKOPATH}
# proc ssh -t root@${IP} "rm -f v3sKoLed; rmmod v3sKoLed.ko; insmod /lib/modules/v3sKoLed.ko; mknod /dev/v3sKoLed c 200 0; echo "mod done""
proc ssh -t root@${IP} "rmmod v3sKoLed.ko; insmod /lib/modules/v3sKoLed.ko; echo "mod done""
proc ssh -t root@${IP} /root/app/v3sAppLed /dev/v3sKoLed $1 $2